package com.woniu.cinema.service.impl;

import java.util.List;
import com.woniu.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.woniu.cinema.mapper.CommentMapper;
import com.woniu.cinema.domain.Comment;
import com.woniu.cinema.service.CommentService;

/**
 * 影片评论Service业务层处理
 *
 * @author yy
 * @date 2023-09-27
 */
@Service
public class CommentServiceImpl implements CommentService
{
    @Autowired
    private CommentMapper commentMapper;

    /**
     * 查询影片评论
     *
     * @param commentId 影片评论ID
     * @return 影片评论
     */
    @Override
    public Comment selectCommentById(Integer commentId)
    {
        return commentMapper.selectCommentById(commentId);
    }

    /**
     * 查询影片评论列表
     *
     * @param comment 影片评论
     * @return 影片评论
     */
    @Override
    public List<Comment> selectCommentList(Comment comment)
    {
        return commentMapper.selectCommentList(comment);
    }

    /**
     * 新增影片评论
     *
     * @param comment 影片评论
     * @return 结果
     */
    @Override
    public int insertComment(Comment comment)
    {
        comment.setCreateTime(DateUtils.getNowDate());
        return commentMapper.insertComment(comment);
    }

    /**
     * 修改影片评论
     *
     * @param comment 影片评论
     * @return 结果
     */
    @Override
    public int updateComment(Comment comment)
    {
        return commentMapper.updateComment(comment);
    }

    /**
     * 批量删除影片评论
     *
     * @param commentIds 需要删除的影片评论ID
     * @return 结果
     */
    @Override
    public int deleteCommentByIds(Integer[] commentIds)
    {
        return commentMapper.deleteCommentByIds(commentIds);
    }

    /**
     * 删除影片评论信息
     *
     * @param commentId 影片评论ID
     * @return 结果
     */
    @Override
    public int deleteCommentById(Integer commentId)
    {
        return commentMapper.deleteCommentById(commentId);
    }

    @Override
    public Comment queryCommentByUserIdAndMovieId(Long userId, Long movieId) {
        Comment comment = new Comment();
        comment.setUserId(userId);
        comment.setMovieId(movieId);

        List<Comment> list  = commentMapper.selectCommentList(comment);
        if (list.size() > 0) {
            return list.get(0);
        }
        return null;
    }
}
